#include <bits/stdc++.h>
using namespace std;

ifstream fin("color.in");
ofstream fout("color.out");

void solve() {
    int n;
    fin >> n;
    int a[n + 1];
    for (int i = 1; i <= n; ++i) fin >> a[i];


    int b[n + 1];
    for (int i = 0; i <= n; ++i) b[i] = 0;
    
    int maxv = 0;
    while (b[0] == 0) {
        int sum = 0;
        for (int i = 1; i <= n; ++i) {
            int j = i - 1;
            while (j >= 1 && b[j] != b[i]) --j;
            if(j >= 1) {
                if (a[i] == a[j]) sum += a[i];
            }
        }

        maxv = max(maxv, sum);

        int j = n;
        while (b[j] == 1) {
            b[j] = 0;
            --j;
        }
        b[j] = 1;
    }

    fout << maxv << endl;
}

int main() {
    int t;
    fin >> t;
    while (t--) solve();
}